<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
defined('_JEXEC') or die('Restricted access');
?>
<?php JHTML::_('behavior.tooltip'); 
JHTML::_( 'behavior.mootools' );
?>


<?php
// Set toolbar items for the page
$role = ArticleflowHelper::getUserRole();
$edit = JRequest::getVar('edit', true);
$text = !$edit ? JText::_('New') : JText::_('Edit');
JToolBarHelper::title(JText::_('Article Flow') . ': <small><small>[ ' . $text . ' ]</small></small>');
JToolBarHelper::save();
ArticleflowHelper::UserPublished();
ArticleflowHelper::ViewHistory();
    if($role == 2)
        ArticleflowHelper::saveComplete();

    
//    if($role !=1)
//    {
//        ArticleflowHelper::UserReviews();
//
//    }
//    else
//    {
//        //ArticleflowHelper::UserEditorial();
//       ArticleflowHelper::UserPublished();
//    }
    if (!$edit) {
        JToolBarHelper::cancel();
    } else {
    // for existing items the button is renamed `close`
    JToolBarHelper::cancel('cancel', 'Close');
    }
JToolBarHelper::help('screen.duyetbai.edit');
$editor = &JFactory::getEditor();
$user_sent ='';
?>

<script language="javascript" type="text/javascript">
		
		var sectioncategories = new Array;
		<?php
		$i = 0;
		foreach ($this->sectioncategories as $k=>$items) {
			foreach ($items as $v) {
				echo "sectioncategories[".$i++."] = new Array( '$k','".addslashes( $v->id )."','".addslashes( $v->title )."' );\n\t\t";
			}
		}
		?>
    function submitbutton(pressbutton) {
        var form = document.adminForm;
        if (pressbutton == 'cancel') {
           
            submitform( pressbutton );
            return;
        }
        
        // do field validation
        if (form.title.value == ""){
            alert( "<?php echo JText::_('Title item must have a title', true); ?>" );
        }  else {
            submitform( pressbutton );
        }
       
        
    }
  
window.addEvent( 'domready', function() {
      
	//$('adminFormComment').addEvent( 'submit', function(e){
       
        $('btnCommentSend').addEvent( 'click', function(e){
           var select = document.adminFormComment.assigned_user.value;
         //   $('ajax-container').empty().addClass('ajax-loading');
            // Stop the form from submitting
           // new Event(e).stop();
       //     var content  =  document.adminFormComment.content.value;
//            var content = docuem
            var url = 'index.php?option=com_articleflow&task=comment';
              new Ajax(url, {
                method: 'post',
                data: 'content='+$('comment-content').get('value')+'&article_id='+$('cid').get('value')+'&user_reciever='+select,
                onComplete: function(response) { 
                  document.adminFormComment.content.value='Nội dung';
                  
                    alert('Gửi ý kiến thành công'); 
                   // $('ajax-container').removeClass('ajax-loading').setHTML( output );
                }
            }).request();
        });
        
});


</script>

<form action="index.php" method="post" name="adminForm">
    <div class="col width-70">
    <table cellspacing="0" cellpadding="0" border="0" width="100%">
        <tr>
            <td valign="top">
                <table  class="adminform">
                    <tr>
                        <td>

                            <?php echo JText::_('Title'); ?>:

                        </td>
                        <td>
                            <input class="text_area" type="text" name="title" id="title" size="40" maxlength="255" value="<?php echo $this->items->title; ?>" />
                        </td>
                        <td>
                            <label>
                                <?php //echo JText::_('Published'); ?>
                            </label>
                        </td>
                        <td>
                            <?php //echo $this->lists['state']; ?>
                            </td>
                        </tr>
                        <tr>
                            <td>

                            <?php echo JText::_('Alias'); ?>:

                            </td>
                            <td>
                                <input class="text_area" type="text" name="alias" id="alias" size="40" maxlength="255" value="<?php echo $this->items->alias; ?>" title="<?php echo JText::_('ALIASTIP'); ?>" />
                            </td>
                            <td>
                                <label for="assigned_user">
                                    <?php echo JText::_('Chuyển tới'); ?>:
                                </label>
                            </td>
                            <td>


                           
                                <?php 
                                 $this->items->assigned_user=23;
                                echo ArticleflowHelper::buildUser($this->items->assigned_user); ?>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <?php echo JText::_('Section'); ?>:
                            </td>
                            <td>

                                <?php
                                echo $this->lists['sectionid2'];
                                //echo $this->lists['sectionid']; ?>
                            </td>
                            <td>
                            <?php echo JText::_('Category'); ?>:
                            </td>
                            <td>
                            <?php
                             echo $this->lists['catid'];
                              
                               ?>
                            </td>
                        </tr>
                    </table>

                </td>

            </tr>
            <tr>
                <td valign="center">
                    Giới thiệu
                    
                            <?php
                               
                                echo $editor->display('introtext', $this->items->introtext, '80%', '350', '75', '20');
                            ?>
                        
                </td>
            </tr>
            <tr>
                <td valign="center">
                    Nội dung
                   
                            <?php
                                // parameters : areaname, content, width, height, cols, rows
                                echo $editor->display('fulltext', $this->items->fulltext, '80%', '550', '75', '20');
                            ?>
                            
                </td>
            </tr>
        </table>
        <input type="hidden" name="option" value="com_articleflow" />
        <input type="hidden" name="cid[]" value="<?php echo $this->items->id; ?>" />
        <input type="hidden" name="task" value="" />
    <?php echo JHTML::_('form.token'); ?>
        </div>
</form>


<div class="col width-30">
  
    <table cellspacing="0" cellpadding="0" border="0" width="100%">
        <tr>
            <td>Danh sách ý kiến đóng góp</td>
        </tr>
        <tr>
            <td>
                <table class="adminlist" >
                    <tbody>
                        <?php
                            $k = 0 ; 
                           // print_r($this->cm_items); die();
                            $j = count($this->cm_items);
                            for($i=0,$n=count($this->cm_items);$i<$n;$i++)
                            {
                                $row = $this->cm_items[$i];
                                
                            
                        ?>
                        <tr class="<?php echo "row$k"; ?>">                          
                            <td width="4%"> <?php echo JText::_('Người gửi'); ?>:</td>
                            <td width="15%" align="left">
                                    <?php 
                                   // echo $this->cm_items[$i]->user_sent;
                                    $model = $this->getModel('articleflow_edit');
                                    $result = $model->getUserNameByCreated($this->cm_items[$i]->user_sent);
                                    $user_sent = $this->cm_items[0]->user_sent;
                                echo $result->name;
                                    ?>
                            </td>
                             
                           
                           
                          
                        </tr>
                        <tr>
                            <td colspan="2">
                                
                                    <?php echo $row->content;?>
                                <div align="right"> <?php echo  date('d-m-Y', strtotime($row->create_date));?></div>
                            </td>
                        </tr>
                        
                        <?php
                        $k = 1 - $k;
                            }
                        ?>
                    </tbody>
                </table>
            </td>
        </tr>
        <tr>
            <td> 
                    <div id="ajax-container">
                        <form name="adminFormComment" method="post" id="adminFormComment">
                        <table  class="adminform" border="1">
                            <tr>
                                <td> <?php echo JText::_('Người nhận'); ?>:</td>
                                <td> <?php $this->items->assigned_user=23;
                                        echo ArticleflowHelper::buildUserName($user_sent); ?></td>
                            </tr>
                            <tr>
                                <td> <?php echo JText::_('Nội dung'); ?>:</td>
                                <td><textarea class="text_area" id="comment-content"  name="content" rows="5" cols="40">Nội dung</textarea></td>
                            </tr>
                            <tr >
                                <td  colspan="2"> <div align="right"><input type="button" id="btnCommentSend" name="btnCommentSend" value="Gửi" /></div></td>
                            </tr>
                        </table>
                            <input type="hidden" id="cid" name="cid" value="<?php echo $this->items->id; ?>" />
                        <?php echo JHTML::_('form.token'); ?>
                    </form>
                </div>

            </td>
        </tr>
   
    </table>
</div>    
